Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String #167

Merged
merged 17 commits into from
Jul 18, 2024
Merged

String #167

merged 17 commits into from
Jul 18, 2024

Conversation

dinosaure
Copy link
Contributor

On top of #166

@dinosaure dinosaure marked this pull request as ready for review April 4, 2024 14:20
@hannesm
Copy link
Member

hannesm commented Apr 4, 2024

The ecdsa_sig stuff is a bit horrible.. I'm unsure whether we should go through Z instead? The downside is that we would construct a Z just to validate (non-negative) and deconstruct it again -- and on the encoding site, just to add or remove some 0x00...

What needs to be done for encoding:

  • if the signature has the high bit set of the first byte, we need to prepend a 0x00 byte (to avoid that being treat as a negative number)
  • if the signature has leading 0x00 bytes, they should be removed (unless the next byte is > 0x7F, where again we need a 0x00 in front) <- this may happen if the signature simply has some leading 0s...

For decoding, the asn.1 integer already takes care of avoiding the redundant form (no superfluous leading 0x00 bytes) -- all we need to check that nobody gave us a negative number (thus first byte must be < 0x80). We cut away a potentially leading 0 since mirage-crypto-ec doesn't like these potentially too long (in terms of too many bytes, although they are 0) values...

@hannesm
Copy link
Member

hannesm commented Apr 8, 2024

Still issues on 32bit architectures and ppc64... need to investigate, will do with some local system to test with.

dinosaure added a commit to dinosaure/mirage-crypto that referenced this pull request Apr 20, 2024
Cstruct.create does this. If we don't initialize bytes with '\000',
Field_element.zero can be something else than '\000'. It's a fix for
mirleft/ocaml-x509#167.
@dinosaure
Copy link
Contributor Author

Tested locally with docker and mirage/mirage-crypto#226 and it's work 🎉.

hannesm added a commit to mirage/mirage-crypto that referenced this pull request Apr 23, 2024
Cstruct.create does this. If we don't initialize bytes with '\000',
Field_element.zero can be something else than '\000'. It's a fix for
mirleft/ocaml-x509#167.

Co-authored-by: Hannes Mehnert <[email protected]>
@hannesm
Copy link
Member

hannesm commented Jun 11, 2024

The last commit represents a serial number to be an unsigned integer with at most 20 octets. This is a breaking change, and makes the behaviour more strict in respect to RFC 5280. Taking into consideration that e.g. the NSS trust anchors serials are fine, my plan is to document and release, and if there's pushback we will revise the checks.

hannesm added a commit to hannesm/opam-repository that referenced this pull request Jun 29, 2024
CHANGES:

### Breaking changes

* mirage-crypto: Poly1305 API now uses string (mirage/mirage-crypto#203 @hannesm)
* mirage-crypto: Poly1305 no longer has type alias "type mac = string"
  (mirage/mirage-crypto#232 @hannesm)
* mirage-crypto: the API uses string instead of cstruct (mirage/mirage-crypto#214 @reynir @hannesm)
* mirage-crypto: Hash module has been removed. Use digestif if you need hash
  functions (mirage/mirage-crypto#213 @hannesm)
* mirage-crypto: the Cipher_block and Cipher_stream modules have been removed,
  its contents is inlined:
  Mirage_crypto.Cipher_block.S -> Mirage_crypto.Block
  Mirage_crypto.Cipher_stream.S -> Mirage_crypto.Stream
  Mirage_crypto.Cipher_block.AES.CTR -> Mirage_crypto.AES.CTR
  (mirage/mirage-crypto#225 @hannesm, suggested in mirage/mirage-crypto#224 by @reynir)
* mirage-crypto-pk: s-expression conversions for private and public keys (Dh,
  Dsa, Rsa) have been removed. You can use PKCS8 for encoding and decoding
  `X509.{Private,Public}_key.{en,de}code_{der,pem}` (mirage/mirage-crypto#208 @hannesm)
* mirage-crypto-pk: in the API, Cstruct.t is no longer present. Instead,
  string is used (mirage/mirage-crypto#211 @reynir @hannesm)
* mirage-crypto-rng: the API uses string instead of Cstruct.t. A new function
  `generate_into : ?g -> bytes -> ?off:int -> int -> unit` is provided
  (mirage/mirage-crypto#212 @hannesm @reynir)
* mirage-crypto-ec: remove NIST P224 support (mirage/mirage-crypto#209 @hannesm @Firobe)
* mirage-crypto: in Uncommon.xor_into the arguments ~src_off and ~dst_off are
  required now (mirage/mirage-crypto#232 @hannesm), renamed to unsafe_xor_into
  (98f01b14f5ebf98ba0e7e9c2ba97ec518f90fddc)
* mirage-crypto-pk, mirage-crypto-rng: remove type alias "type bits = int"
  (mirage/mirage-crypto#236 @hannesm)

### Bugfixes

* mirage-crypto (32 bit systems): CCM with long adata (mirage/mirage-crypto#207 @reynir)
* mirage-crypto-ec: fix K_gen for bitlen mod 8 != 0 (reported in mirage/mirage-crypto#105 that
  P521 test vectors don't pass, re-reported mirage/mirage-crypto#228, fixed mirage/mirage-crypto#230 @Firobe)
* mirage-crypto-ec: zero out bytes allocated for Field_element.zero (reported
  mirleft/ocaml-x509#167, fixed mirage/mirage-crypto#226 @dinosaure)

### Data race free

* mirage-crypto (3DES): avoid global state in key derivation (mirage/mirage-crypto#223 @hannesm)
* mirage-crypto-rng: use atomic instead of reference to be domain-safe (mirage/mirage-crypto#221
  @dinosaure @reynir @hannesm)
* mirage-crypto, mirage-crypto-rng, mirage-crypto-pk, mirage-crypto-ec:
  avoid global buffers, use freshly allocated strings/bytes instead, avoids
  data races (mirage/mirage-crypto#186 mirage/mirage-crypto#219 @dinosaure @reynir @hannesm)

### Other changes

* mirage-crypto: add {de,en}crypt_into functions (and unsafe variants) to allow
  less buffer allocations (mirage/mirage-crypto#231 @hannesm)
* mirage-crypto-rng-miou: new package which adds rng support with miou
  (mirage/mirage-crypto#227 @dinosaure)
* PERFORMANCE mirage-crypto: ChaCha20/Poly1305 use string instead of Cstruct.t,
  ChaCha20 interface unchanged, performance improvement roughly 2x
  (mirage/mirage-crypto#203 @hannesm @reynir)
* mirage-crypto-ec, mirage-crypto-pk, mirage-crypto-rng: use digestif for
  hashes (mirage/mirage-crypto#212 mirage/mirage-crypto#215 @reynir @hannesm)
* mirage-crypto-rng: use a set for entropy sources instead of a list
  (mirage/mirage-crypto#218 @hannesm)
* mirage-crypto-rng-mirage: provide a module type S (for use instead of
  mirage-random in mirage) (mirage/mirage-crypto#234 @hannesm)
x509.opam Outdated Show resolved Hide resolved
x509.opam Outdated Show resolved Hide resolved
x509.opam Outdated Show resolved Hide resolved
x509.opam Outdated Show resolved Hide resolved
x509.opam Outdated Show resolved Hide resolved
x509.opam Outdated Show resolved Hide resolved
x509.opam Outdated Show resolved Hide resolved
x509.opam Outdated Show resolved Hide resolved
x509.opam Outdated Show resolved Hide resolved
x509.opam Outdated Show resolved Hide resolved
@hannesm
Copy link
Member

hannesm commented Jul 17, 2024

I removed the pin depends. This looks good to go, all we need is a changes entry, and a decision whether to add #164 to the release (it'll be a 1.0, I'm happy to include #164).

I'm fine to merge, I can as well tag a release on Github once we're good. Since I don't have my laptop this month, I won't be able to do a dune-release / opam-publish (or PR to opam-repository), but I'm sure once a release is here someone (@dinosaure ?) can run opam-publish to get something onto opam-repository.

@dinosaure
Copy link
Contributor Author

Yes, if the tag is available and the tarball, I will be happy to make a release into opam-repository then 👍

dinosaure added a commit to dinosaure/ocaml-x509 that referenced this pull request Jul 17, 2024
CHANGES.md Show resolved Hide resolved
dinosaure added a commit to dinosaure/ocaml-x509 that referenced this pull request Jul 17, 2024
val decode_pkcs1_digest_info : Cstruct.t ->
(Mirage_crypto.Hash.hash * Cstruct.t, [> `Msg of string ]) result
val decode_pkcs1_digest_info : string ->
([ `MD5 | `SHA1 | `SHA224 | `SHA256 | `SHA384 | `SHA512 ] * string, [> `Msg of string ]) result
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking at this, I'm unsure. sometimes Digestif.hash' is used, but here and below it is explicit. Is this intentional (sorry I lost context and am on a mobile phone screen)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Digestif.hash' has more variants that this one. On the interface level, if we use Digestif.hash', this would mean we'd have to handle cases like RIPEMD160, for example, in the implementation. To avoid unnecessary cases, this is why we make variants explicit.

| `Bad_encoding of Distinguished_name.t * string * Cstruct.t
| `Hash_not_allowed of Distinguished_name.t * Mirage_crypto.Hash.hash
| `Bad_encoding of Distinguished_name.t * string * string
| `Hash_not_allowed of Distinguished_name.t * [ `MD5 | `SHA1 | `SHA224 | `SHA256 | `SHA384 | `SHA512 ]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

@@ -1078,11 +1076,11 @@ module OCSP : sig
type cert_id

(** [create_cert_id issuer serial] creates cert_id for this serial *)
val create_cert_id : ?hash:Mirage_crypto.Hash.hash -> Certificate.t -> Z.t ->
val create_cert_id : ?hash:[ `MD5 | `SHA1 | `SHA224 | `SHA256 | `SHA384 | `SHA512 ] -> Certificate.t -> string ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and again, explicit hashes instead of Digestif.hash'

CHANGES.md Show resolved Hide resolved
@hannesm hannesm merged commit f453f70 into mirleft:main Jul 18, 2024
1 check passed
@hannesm
Copy link
Member

hannesm commented Jul 18, 2024

thanks a lot

@dinosaure dinosaure deleted the string branch July 18, 2024 10:32
dinosaure added a commit to dinosaure/opam-repository that referenced this pull request Jul 22, 2024
What's Changed

- Fix mixup of subject and hash in error message by @reynir in
  mirleft/ocaml-x509#165
- Use string instead of cstruct by @dinosaure in mirleft/ocaml-x509#167
- Rename Authenticator.server_{cert,key}_fingerprint by @reynir in mirleft/ocaml-x509#164
- Add Certificate.fold_decode_pem_multiple by @art-w in
  mirleft/ocaml-x509#169

New Contributors

- @art-w made their first contribution in mirleft/ocaml-x509#169
avsm pushed a commit to avsm/opam-repository that referenced this pull request Sep 5, 2024
CHANGES:

### Breaking changes

* mirage-crypto: Poly1305 API now uses string (mirage/mirage-crypto#203 @hannesm)
* mirage-crypto: Poly1305 no longer has type alias "type mac = string"
  (mirage/mirage-crypto#232 @hannesm)
* mirage-crypto: the API uses string instead of cstruct (mirage/mirage-crypto#214 @reynir @hannesm)
* mirage-crypto: Hash module has been removed. Use digestif if you need hash
  functions (mirage/mirage-crypto#213 @hannesm)
* mirage-crypto: the Cipher_block and Cipher_stream modules have been removed,
  its contents is inlined:
  Mirage_crypto.Cipher_block.S -> Mirage_crypto.Block
  Mirage_crypto.Cipher_stream.S -> Mirage_crypto.Stream
  Mirage_crypto.Cipher_block.AES.CTR -> Mirage_crypto.AES.CTR
  (mirage/mirage-crypto#225 @hannesm, suggested in mirage/mirage-crypto#224 by @reynir)
* mirage-crypto-pk: s-expression conversions for private and public keys (Dh,
  Dsa, Rsa) have been removed. You can use PKCS8 for encoding and decoding
  `X509.{Private,Public}_key.{en,de}code_{der,pem}` (mirage/mirage-crypto#208 @hannesm)
* mirage-crypto-pk: in the API, Cstruct.t is no longer present. Instead,
  string is used (mirage/mirage-crypto#211 @reynir @hannesm)
* mirage-crypto-rng: the API uses string instead of Cstruct.t. A new function
  `generate_into : ?g -> bytes -> ?off:int -> int -> unit` is provided
  (mirage/mirage-crypto#212 @hannesm @reynir)
* mirage-crypto-ec: remove NIST P224 support (mirage/mirage-crypto#209 @hannesm @Firobe)
* mirage-crypto: in Uncommon.xor_into the arguments ~src_off and ~dst_off are
  required now (mirage/mirage-crypto#232 @hannesm), renamed to unsafe_xor_into
  (98f01b14f5ebf98ba0e7e9c2ba97ec518f90fddc)
* mirage-crypto-pk, mirage-crypto-rng: remove type alias "type bits = int"
  (mirage/mirage-crypto#236 @hannesm)

### Bugfixes

* mirage-crypto (32 bit systems): CCM with long adata (mirage/mirage-crypto#207 @reynir)
* mirage-crypto-ec: fix K_gen for bitlen mod 8 != 0 (reported in mirage/mirage-crypto#105 that
  P521 test vectors don't pass, re-reported mirage/mirage-crypto#228, fixed mirage/mirage-crypto#230 @Firobe)
* mirage-crypto-ec: zero out bytes allocated for Field_element.zero (reported
  mirleft/ocaml-x509#167, fixed mirage/mirage-crypto#226 @dinosaure)

### Data race free

* mirage-crypto (3DES): avoid global state in key derivation (mirage/mirage-crypto#223 @hannesm)
* mirage-crypto-rng: use atomic instead of reference to be domain-safe (mirage/mirage-crypto#221
  @dinosaure @reynir @hannesm)
* mirage-crypto, mirage-crypto-rng, mirage-crypto-pk, mirage-crypto-ec:
  avoid global buffers, use freshly allocated strings/bytes instead, avoids
  data races (mirage/mirage-crypto#186 mirage/mirage-crypto#219 @dinosaure @reynir @hannesm)

### Other changes

* mirage-crypto: add {de,en}crypt_into functions (and unsafe variants) to allow
  less buffer allocations (mirage/mirage-crypto#231 @hannesm)
* mirage-crypto-rng-miou: new package which adds rng support with miou
  (mirage/mirage-crypto#227 @dinosaure)
* PERFORMANCE mirage-crypto: ChaCha20/Poly1305 use string instead of Cstruct.t,
  ChaCha20 interface unchanged, performance improvement roughly 2x
  (mirage/mirage-crypto#203 @hannesm @reynir)
* mirage-crypto-ec, mirage-crypto-pk, mirage-crypto-rng: use digestif for
  hashes (mirage/mirage-crypto#212 mirage/mirage-crypto#215 @reynir @hannesm)
* mirage-crypto-rng: use a set for entropy sources instead of a list
  (mirage/mirage-crypto#218 @hannesm)
* mirage-crypto-rng-mirage: provide a module type S (for use instead of
  mirage-random in mirage) (mirage/mirage-crypto#234 @hannesm)
avsm pushed a commit to avsm/opam-repository that referenced this pull request Sep 5, 2024
What's Changed

- Fix mixup of subject and hash in error message by @reynir in
  mirleft/ocaml-x509#165
- Use string instead of cstruct by @dinosaure in mirleft/ocaml-x509#167
- Rename Authenticator.server_{cert,key}_fingerprint by @reynir in mirleft/ocaml-x509#164
- Add Certificate.fold_decode_pem_multiple by @art-w in
  mirleft/ocaml-x509#169

New Contributors

- @art-w made their first contribution in mirleft/ocaml-x509#169
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants